package com.lanyan.system.service.impl;

import java.util.List;
import java.util.stream.Collectors;
        import com.lanyan.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.lanyan.common.utils.StringUtils;
import com.lanyan.system.mapper.ClassifyMapper;
import com.lanyan.system.domain.Classify;
import com.lanyan.system.domain.vo.ClassifyVo;
import com.lanyan.system.service.IClassifyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 分类Service业务层处理
 *
 * @author lanyan
 * @date 2024-11-26
 */
@Service
public class ClassifyServiceImpl  extends ServiceImpl<ClassifyMapper,Classify> implements IClassifyService

{
    @Autowired
    private ClassifyMapper classifyMapper;

    /**
     * 查询分类
     *
     * @param classifyId 分类主键
     * @return 分类
     */
    @Override
    public Classify selectClassifyByClassifyId(Long classifyId)
    {
        return this.getById(classifyId);
    }

    /**
     * 查询分类Vo列表
     *
     * @param classify 分类
     * @return 分类
     */
    @Override
    public List<ClassifyVo> selectClassifyVoList(Classify classify)
    {
        return selectClassifyList(classify)
                .stream()
                .map(x -> (ClassifyVo)x)
                .collect(Collectors.toList());
    }
    /**
     * 查询分类列表
     *
     * @param classify 分类
     * @return 分类
     */
    @Override
    public List<Classify> selectClassifyList(Classify classify)
    {
        LambdaQueryChainWrapper<Classify> wrapper = this.lambdaQuery().eq(Classify::getDelFlag,"0");
        if (StringUtils.isNotEmpty(classify.getName())) {
            wrapper.like(Classify::getName, classify.getName());
        }
        if (StringUtils.isNotEmpty(classify.getSuperior())) {
            wrapper.eq(Classify::getSuperior, classify.getSuperior());
        }
        return wrapper.list();
    }

        /**
         * 新增分类
         *
         * @param classify 分类
         * @return 结果
         */
    @Override
        public boolean insertClassify(Classify classify)
        {
                    classify.setCreateTime(DateUtils.getNowDate());
                return this.save(classify);
        }

        /**
         * 修改分类
         *
         * @param classify 分类
         * @return 结果
         */
    @Override
        public boolean updateClassify(Classify classify)
        {
                    classify.setUpdateTime(DateUtils.getNowDate());
            return this.updateById(classify);
        }

        /**
         * 批量删除分类
         *
         * @param classifyIds 需要删除的分类主键
         * @return 结果
         */
    @Override
        public boolean deleteClassifyByClassifyIds(Long[] classifyIds)
        {
            return this.lambdaUpdate().set(Classify::getDelFlag,"1").in(Classify::getClassifyId,classifyIds).update();
        }

        /**
         * 删除分类信息
         *
         * @param classifyId 分类主键
         * @return 结果
         */
    @Override
        public boolean deleteClassifyByClassifyId(Long classifyId)
        {
            return this.lambdaUpdate().set(Classify::getDelFlag,"1").eq(Classify::getClassifyId,classifyId).update();
        }
    }
